package com.example.music.lrc;


import java.util.ArrayList;
import java.util.List;


public class LrcRow implements Comparable<LrcRow>{
    public final static String TAG = "LrcRow";

    public String strTime;

    public long time;

    public String content;


    public LrcRow(){}

    public LrcRow(String strTime,long time,String content){
        this.strTime = strTime;
        this.time = time;
        this.content = content;
    }

    @Override
    public String toString() {
        return "[" + strTime + " ]"  + content;
    }

    public static List<LrcRow> createRows(String standardLrcLine){
            String times = standardLrcLine.replace("[", "-").replace("]", ",,");
            String arrTimes[] = times.split("-");
            List<LrcRow> listTimes = new ArrayList<LrcRow>();
            for(String temp : arrTimes){
                if(temp.trim().length() == 0){
                    continue;
                }
                String[] split = temp.split(",,");
                if(split.length<2){
                    continue;
                }
                LrcRow lrcRow = new LrcRow(split[0], timeConvert(split[0]), split[1]);
                listTimes.add(lrcRow);
            }
            return listTimes;
    }

    private static long timeConvert(String timeString){
        timeString = timeString.replace('.', ':');
        String[] times = timeString.split(":");
        return Integer.valueOf(times[0]) * 60 * 1000 +
                Integer.valueOf(times[1]) * 1000 +
                Integer.valueOf(times[2]) ;
    }


    @Override
    public int compareTo(LrcRow another) {
        return (int)(this.time - another.time);
    }
}

